package com.ibiaoke.common.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * Created by huhaichao on 2017/5/26.
 */
public class UrlUtils {
    public static final String ENCODING = "utf-8";

    public static String encodeUrl(String url) {
        try {
            if(url==null){
                return "";
            }
            return URLEncoder.encode(url, ENCODING);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String decodeUrl(String url) {
        try {
            if(url==null){
                return "";
            }
            return URLDecoder.decode(url, ENCODING);

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "";
        }
    }
}
